'use strict';

Object.defineProperty(exports, '__esModule', {
  value: true
});
exports.default = void 0;

function _defineProperty(obj, key, value) {
  if (key in obj) {
    Object.defineProperty(obj, key, {
      value: value,
      enumerable: true,
      configurable: true,
      writable: true
    });
  } else {
    obj[key] = value;
  }
  return obj;
}

const defaultNow = (function (Date) {
  return function () {
    return new Date().getTime();
  };
})(Date);

class Timer {
  constructor(options) {
    _defineProperty(this, 'start', void 0);
    _defineProperty(this, 'time', void 0);
    _defineProperty(this, 'reset', void 0);
    _defineProperty(this, 'start', void 0);
    _defineProperty(this, 'pause', void 0);
    _defineProperty(this, 'continue', void 0);
    _defineProperty(this, 'destory', void 0);
    options = options || {};
    console.log(options);
    this._time = void 0 === options.duration ? 1 : options.duration;
    this._intervalId = null;
    this._interval = void 0 === options.interval ? 1e3 : options.interval;
    this._isPaused = false;
    this._intervalCallBack =  void 0 === options.intervalCallBack ? null : options.intervalCallBack;
    this._endCallback = void 0 === options.endCallback ? null : options.endCallback;
    this.time = function () {
      return this._time;
    };
    this.reset = function () {
      clearInterval(this._intervalId), this._intervalId = null, this._time = e || 1;
    };

    this.start = function () {
      var e = this;
      this._intervalId || (this._intervalId = setInterval((function() {
          e._isPaused || (e._time--, e._intervalCallBack && e._intervalCallBack(e._time), 0 === e._time && (clearInterval(e._intervalId), e._intervalId = null, e._endCallback && e._endCallback()))
      }), this._interval));
    };

    this.pause = function () {
      this._intervalId ? this._isPaused = !0 : console.log("\u6682\u505c\u65e0\u6548");
    };

    this.continue = function () {
      this._intervalId ? this._isPaused = !1 : console.log("\u91cd\u542f\u65e0\u6548");
    };

    this.destory = function () {
      this._intervalId && clearInterval(this._intervalId);
    };


  }
}

exports.default = Timer;
